import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.Callable;

public class MyCallable implements Callable<Integer> {
    static ArrayList<Integer> List = new ArrayList<>();

    public MyCallable(ArrayList<Integer> list) {
        List = list;
    }

    @Override
    public Integer call() throws Exception {
        ArrayList<Integer> list = new ArrayList<>();
        while(true) {
            synchronized(MyCallable.class) {
                if(List.isEmpty()) {
                    break;
                } else {
                    Collections.shuffle(List);
                    Integer result = List.remove(0);
                    list.add(result);
                }
            }
        }
        if(list.isEmpty()) {
            return null;
        } else {
            return Collections.max(list);
        }
    }
}
